.SUFFIXES: .o .cpp .cxx

CXX=g++
DEP_FILE=Makefile.dep
CPPFLAGS= -g -ggdb -DEBUG -D_DEBUG
#CPPFLAGS= -O2 -DNDEBUG -DNO_DEBUG
CPPFLAGS+= -fPIC -W -Wall -pthread -std=c++11


#Linux에서 플랫폼 알아내기
UNAME_P:=$(shell uname -p)
ifeq ($(UNAME_P), x86_64)
    PLATFORM=x86_64
else
    # Android
    PLATFORM=armeabi
endif

SRC=$(wildcard *.cpp)
#SRC+=$(wildcard other_dir/*.cpp) # 추가적인 디렉토리가 있는 경우
OBJ=$(SRC:.cpp=.o)
LIB_DIR=lib/


TARGET_SRC=$(wildcard *.cxx)
TARGET_NAME=$(TARGET_SRC:%.cxx=%)
TARGET_LIB=libcpp_barbecue


INC=-I./
LIBS=$(LIB_DIR)$(TARGET_LIB)
LIBS+= -lpthread

.cpp.o:
	-@echo "== Compile $< =="
	$(CXX) $(CPPFLAGS) -c $< -o $@ $(INC)

.cxx.o:
	$(CXX) $(CPPFLAGS) -c $< $(INC)


all: $(TARGET_NAME)

#lib: $(OBJ)
#	ar rsc $(LIB_DIR)$(LIB_NAME).a $(OBJ)
#	ranlib $(LIB_DIR)$(LIB_NAME).a 


slib: $(OBJ)
	$(CXX) -shared -Wl,-soname,$(TARGET_LIB).so $(CPPFLAGS) -o $(LIB_DIR)$(TARGET_LIB).so $(OBJ)


.SECONDEXPANSION:
$(TARGET_NAME): $$@.o $(OBJ)
	$(CXX) -o $(BIN)$@ $< $(OBJ) -L $(LIB_DIR)  $(LIB) $(INC)

#exe:
#    ?$(CXX) $(CPPFLAGS) -o $(BIN)$(TARGET) $(OBJ) main.o $(LIBS) $(INC)



dep:
	$(CXX) -MM $(SRC) $(TARGET_SRC) > $(DEP_FILE)


clean:
	rm -f *.o $(DEP_FILE) *~
	rm -f $(BIN)$(TARGET_NAME)
	rm -f $(LIB_DIR)$(TARGET_LIB).*

